feat: appeal command#233
Conversation
WalkthroughA new "appeal" transaction command is introduced into the CLI, allowing users to appeal a transaction by its hash with optional RPC endpoint specification. Supporting logic, command registration, and comprehensive tests for both the action and command interface have been added, along with necessary integration into the CLI initialization. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant AppealAction
participant Client
participant Spinner
User->>CLI: Run "appeal <txId> [--rpc]"
CLI->>AppealAction: appeal({ txId, rpc })
AppealAction->>Client: getClient(rpc)
AppealAction->>Client: initializeConsensusSmartContract()
AppealAction->>Spinner: start("Appealing transaction...")
AppealAction->>Client: appealTransaction(txId)
AppealAction->>Client: waitForReceipt(txId, retries)
alt Success
AppealAction->>Spinner: succeed(result)
else Error
AppealAction->>Spinner: fail(error)
end
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error Exit handler never called! ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/commands/transactions/appeal.ts (2)
4-6: Consider removing the unused interface or refactor method parameters.The
AppealOptionsinterface is defined but never used in this file. Either remove it if not needed, or refactor the method parameters to use it for better type consistency.If you intend to use this interface, apply this diff to improve type safety:
async appeal({ txId, rpc, }: { txId: TransactionHash; - rpc?: string; + options?: AppealOptions; }): Promise<void> { - const client = await this.getClient(rpc); + const client = await this.getClient(options?.rpc);Or simply remove the unused interface:
-export interface AppealOptions { - rpc?: string; -}
9-11: Remove the unnecessary constructor.The constructor only calls
super()with no additional logic, making it redundant. TypeScript will automatically call the parent constructor.Apply this diff to remove the unnecessary constructor:
- constructor() { - super(); - }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/commands/transactions/appeal.ts(1 hunks)src/commands/transactions/index.ts(1 hunks)src/index.ts(2 hunks)tests/actions/appeal.test.ts(1 hunks)tests/commands/appeal.test.ts(1 hunks)tests/index.test.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
tests/actions/appeal.test.ts (1)
src/commands/transactions/appeal.ts (1)
AppealAction(8-39)
tests/commands/appeal.test.ts (2)
src/commands/transactions/index.ts (1)
initializeTransactionsCommands(5-16)src/commands/transactions/appeal.ts (1)
AppealAction(8-39)
src/commands/transactions/index.ts (1)
src/commands/transactions/appeal.ts (2)
AppealOptions(4-6)AppealAction(8-39)
src/index.ts (1)
src/commands/transactions/index.ts (1)
initializeTransactionsCommands(5-16)
src/commands/transactions/appeal.ts (1)
src/lib/actions/BaseAction.ts (1)
BaseAction(11-117)
🪛 Biome (1.9.4)
src/commands/transactions/appeal.ts
[error] 9-11: This constructor is unnecessary.
Unsafe fix: Remove the unnecessary constructor.
(lint/complexity/noUselessConstructor)
🔇 Additional comments (16)
tests/index.test.ts (1)
44-46: LGTM: Mock follows established pattern.The mock for the transactions commands module is consistent with the existing mocking pattern and properly supports testing of the CLI initialization.
src/index.ts (2)
13-13: LGTM: Clean integration following established pattern.The import follows the same pattern as other command module imports.
25-25: LGTM: Proper command initialization.The function call is correctly placed in the initialization sequence and follows the established pattern.
tests/commands/appeal.test.ts (4)
1-21: LGTM: Well-structured test setup.The test suite setup is comprehensive with proper imports, mocking, and cleanup. The mock transaction ID format is appropriate for testing transaction hash inputs.
22-28: LGTM: Default options test is thorough.The test correctly verifies that AppealAction is instantiated and its appeal method is called with the expected parameters.
30-44: LGTM: Custom RPC test covers important functionality.The test properly verifies that custom RPC URLs are passed through correctly to the AppealAction.
51-57: LGTM: Error handling test uses correct approach.The use of
exitOverride()is the proper way to test commander error handling without causing the test process to exit.src/commands/transactions/index.ts (2)
1-3: LGTM: Proper imports and type usage.The imports are clean and use appropriate TypeScript types from genlayer-js.
5-16: LGTM: Well-implemented command registration.The command definition is clear and follows CLI best practices:
- Required transaction ID argument with proper typing
- Optional RPC flag for flexibility
- Clean action implementation with proper instantiation and method call
- Consistent return pattern
tests/actions/appeal.test.ts (5)
1-34: LGTM: Excellent test setup with proper mocking.The test setup is comprehensive with appropriate mocking of external dependencies and internal methods. The mock structure properly isolates the unit under test.
35-51: LGTM: Thorough success scenario test.The test properly verifies the appeal transaction flow and confirms that success feedback is provided correctly.
53-62: LGTM: Comprehensive error handling test.The test correctly verifies that errors are caught and appropriate failure feedback is provided.
64-87: LGTM: Custom RPC functionality well tested.The test properly verifies that custom RPC URLs are passed to the client creation and the appeal operation executes correctly.
89-98: LGTM: Consensus contract initialization properly tested.The test ensures that the consensus smart contract is initialized before performing the appeal operation, which is a critical requirement.
src/commands/transactions/appeal.ts (2)
1-2: LGTM - Clean imports with proper typing.The imports correctly use the
TransactionHashtype from genlayer-js and extend the establishedBaseActionpattern.
13-38: Well-implemented appeal method with proper error handling.The method implementation follows established patterns from
BaseAction:
- Properly uses
getClient()with optional RPC parameter- Initializes consensus smart contract before operation
- Uses spinner for user feedback
- Implements comprehensive error handling
- Follows the async/await pattern consistently
The retry configuration (100 retries, 5-second intervals) provides reasonable defaults for transaction confirmation.
Add Appeal Transaction Command
Summary
Implements a new
appealcommand that allows users to appeal transactions by their hash. The command follows the established CLI architecture pattern and includes comprehensive test coverage.Changes
🚀 New Features
appeal <txId>command to appeal transactionssrc/commands/transactions/folder structure--rpcparameter for custom network endpoints🏗️ Implementation Details
AppealActionextendsBaseActionfollowing established patternsclient.appealTransaction()and waits for transaction receipt📁 File Structure
🧪 Testing
Action Tests (
tests/actions/appeal.test.ts):Command Tests (
tests/commands/appeal.test.ts):🔧 Usage
✨ Code Quality
TransactionHashtype🔗 Dependencies
genlayer-jsclientBaseActioninfrastructureTesting: ✅ All tests pass
Type Safety: ✅ Full TypeScript coverage
Documentation: ✅ Inline code documentation
Architecture: ✅ Follows established patterns
Summary by CodeRabbit
New Features
Tests